package com.sk.bilibili.utils;

import static com.sk.bilibili.utils.StringUtils.str;

import android.content.res.ColorStateList;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.sk.bilibili.R;
import com.sk.bilibili.bean.Focus;
import com.sk.bilibili.bean.Member;
import com.sk.bilibili.dto.MemberExtra;

public class ViewUtils {

    public static void handleFocus(TextView textView, Member member) {
        if(member.getId().equals(DataUtils.getMemberId())){
            textView.setVisibility(View.GONE);
        }else {
            textView.setVisibility(View.VISIBLE);
            textView.setText(member.getExtra().getFocus()==null?"+关注":"取消关注");
        }
    }

    private static final int[] LEVEL_RES={R.drawable.lv0,R.drawable.lv1,R.drawable.lv2,R.drawable.lv3,R.drawable.lv4,
            R.drawable.lv5,R.drawable.lv6};

    public static int getLevelImage(Integer grade) {
        return LEVEL_RES[grade];
    }

    public static void switchFocus(TextView textView, Member member) {
        MemberExtra extra = member.getExtra();
        if(extra.getFocus()==null){
            extra.setFocus(new Focus());
            textView.setText("取消关注");
        }else {
            extra.setFocus(null);
            textView.setText("+关注");
        }
    }

    public static void tint(TextView textView, Boolean value) {
        if(value)textView.setCompoundDrawableTintList(ColorStateList.valueOf(0xFFfb7299));
    }

    public static void tint(ImageView imageView, Boolean value) {
        if(value)imageView.setImageTintList(ColorStateList.valueOf(0xFFfb7299));
    }

    private static final int[] RES={R.drawable.rank1,R.drawable.rank2,R.drawable.rank3,
            R.drawable.rank};

    public static void handleRank(TextView textView, int pos) {
        if(pos<3){
            textView.setBackgroundResource(RES[pos]);
            textView.setText("");
        }else {
            textView.setBackgroundResource(RES[3]);
            textView.setText(str(pos+1));
        }
    }

}